/*******************************************************************************
 * Copyright 2011 Mauro Luigi Drago (drago.luigi@gmail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
package com.bytenose.extrautils.patterns.dispatcher;

/**
 * An enumeration defining standard comparison operators against numeric values.
 * This enumeration also provides convenient methods to evaluate the comparison
 * against specified values.
 * 
 * @author Mauro Luigi Drago
 * 
 */
public enum ComparisonOp {
	/** The available operators */
	EQ, GEQ, LEQ, LESS, GREATER;

	/**
	 * Evaluates the comparison for the specified {@code integer} values.
	 * 
	 * @param arg1
	 *            the first value.
	 * @param arg2
	 *            the second value.
	 * @return the result.
	 */
	public boolean eval(int arg1, int arg2) {
		switch (this) {
		case EQ:
			return arg1 == arg2;
		case GEQ:
			return arg1 >= arg2;
		case LEQ:
			return arg1 <= arg2;
		case LESS:
			return arg1 < arg2;
		case GREATER:
		default:
			return arg1 > arg2;
		}
	}

	/**
	 * Evaluates the comparison for the specified {@code float} values.
	 * 
	 * @param arg1
	 *            the first value.
	 * @param arg2
	 *            the second value.
	 * @return the result.
	 */
	public boolean eval(float arg1, float arg2) {
		switch (this) {
		case EQ:
			return arg1 == arg2;
		case GEQ:
			return arg1 >= arg2;
		case LEQ:
			return arg1 <= arg2;
		case LESS:
			return arg1 < arg2;
		case GREATER:
		default:
			return arg1 > arg2;
		}
	}

	/**
	 * Evaluates the comparison for the specified {@code double} values.
	 * 
	 * @param arg1
	 *            the first value.
	 * @param arg2
	 *            the second value.
	 * @return the result.
	 */
	public boolean eval(double arg1, double arg2) {
		switch (this) {
		case EQ:
			return arg1 == arg2;
		case GEQ:
			return arg1 >= arg2;
		case LEQ:
			return arg1 <= arg2;
		case LESS:
			return arg1 < arg2;
		case GREATER:
		default:
			return arg1 > arg2;
		}
	}
};